package com.qf.service.impl;

import com.qf.dao.RefundRecordDao;
import com.qf.model.entity.RefundRecord;
import com.qf.service.RefundRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * (RefundRecord)表服务实现类
 *
 * @author makejava
 * @since 2024-05-06 11:30:00
 */
@Service("refundRecordService")
public class RefundRecordServiceImpl implements RefundRecordService {
    @Autowired
    private RefundRecordDao refundRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public RefundRecord queryById(Integer id) {
        return this.refundRecordDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @Override
    public List<RefundRecord> queryByPage(Integer pageNum) {
        return this.refundRecordDao.queryAllByLimit();
    }

    @Override
    public List<RefundRecord> selectOutpatientRechargeByCondition(Map<String, Object> map) {
        return refundRecordDao.selectOutpatientRechargeByCondition(map);
    }

    /**
     * 新增数据
     *
     * @param refundRecord 实例对象
     * @return 实例对象
     */
    @Override
    public RefundRecord insert(RefundRecord refundRecord, HttpSession session) {
        RefundRecord rr = (RefundRecord) session.getAttribute("refundRecord");
        rr.setOperationTime(new Date());
        this.refundRecordDao.insert(refundRecord);
        return refundRecord;
    }

    /**
     * 修改数据
     *
     * @param refundRecord 实例对象
     * @return 实例对象
     */
    @Override
    public RefundRecord update(RefundRecord refundRecord) {
        this.refundRecordDao.update(refundRecord);
        return this.queryById(refundRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.refundRecordDao.deleteById(id) > 0;
    }
}
